home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
fbuilder
/
delphi
/
demos
/
mainform.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
15KB
|
538 lines
{ FormulaBuilder 1.0 }
{ YGB Software, Inc. }
{ Copyright 1995 Clayton Collie }
{ All Rights Reserved }
{* Main Form of the main FormulaBuilder Demo *}
unit Mainform;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, TabNotBk, StdCtrls, Buttons, ExtCtrls, DB,
DBTables, Grids, DBGrids,DBCtrls,
FBCalc,FBComp,FBDBComp,
FiltrFrm,FuncDlg,extfunc,
DBExprFm, VBXCtrl, Chart2fx, Outline,
fb_rtti,FBRTCOMP;
type
TMainDemoFm = class(TForm)
Notebook: TTabbedNotebook;
ResultsPanel: TPanel;
Panel1: TPanel;
ExpressionListbox: TListBox;
Panel2: TPanel;
btnFunctions: TBitBtn;
CancelBtn: TBitBtn;
SpeedButton2: TSpeedButton;
CustomerGrid: TDBGrid;
CustomerTable: TTable;
CustomerDataSource: TDataSource;
Panel5: TPanel;
OrdersGrid: TDBGrid;
OrdersTable: TTable;
OrdersDataSource: TDataSource;
Panel8: TPanel;
OrdersResultPanel: TPanel;
Panel9: TPanel;
cbxApplyCustomerFilter: TCheckBox;
OrdersTableOrderNo: TFloatField;
OrdersTableCustNo: TFloatField;
OrdersTableSaleDate: TDateTimeField;
OrdersTableShipDate: TDateTimeField;
OrdersTableEmpNo: TIntegerField;
OrdersTableTerms: TStringField;
OrdersTablePaymentMethod: TStringField;
OrdersTableItemsTotal: TCurrencyField;
OrdersTableTaxRate: TFloatField;
OrdersTableFreight: TCurrencyField;
OrdersTableAmountPaid: TCurrencyField;
btnCustomerFilter: TBitBtn;
btnOrdersFilter: TBitBtn;
cbxApplyOrdersFilter: TCheckBox;
Formula: TBitBtn;
ChartFX1: TChartFX;
GroupBox1: TGroupBox;
ResultMemo: TMemo;
ExpressionGroupBox: TGroupBox;
ExpressionCombo: TComboBox;
VariablesBtn: TSpeedButton;
CalcBtn: TSpeedButton;
Panel3: TPanel;
FormulaEdit: TEdit;
XMinEdit: TEdit;
XMaxEdit: TEdit;
NumPtsEdit: TEdit;
btnDrawGraph: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
newFuncsCombo: TComboBox;
NewFuncsListbox: TListBox;
RunBtn: TSpeedButton;
runmemo: TMemo;
RegisterFuncBtn: TBitBtn;
UnregisterBtn: TBitBtn;
HelpBtn: TBitBtn;
btnAbout: TSpeedButton;
Bevel1: TBevel;
SimpleExpression: TExpression;
CustomersFilter: TDSFilter;
OrdersFilter: TDSFilter;
OrdersExpression: TDBExpression;
lblCustomerGrid: TLabel;
lblOrdersGrid: TLabel;
CustomerTableCustNo: TFloatField;
CustomerTableCompany: TStringField;
CustomerTableAddr1: TStringField;
CustomerTableCity: TStringField;
CustomerTableState: TStringField;
CustomerTableZip: TStringField;
CustomerTableCountry: TStringField;
CustomerTablePhone: TStringField;
CustomerTableFAX: TStringField;
CustomerTableTaxRate: TFloatField;
CustomerTableContact: TStringField;
CustomerTableLastInvoiceDate: TDateTimeField;
lblDemo: TLabel;
BitBtn1: TBitBtn;
Panel4: TPanel;
Panel6: TPanel;
Memo2: TMemo;
MainLabel: TLabel;
procedure btnFunctionsClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FilterBtnClick(Sender: TObject);
procedure btnOrdersFilterClick(Sender: TObject);
procedure cbxApplyCustomerFilterClick(Sender: TObject);
procedure FormulaClick(Sender: TObject);
procedure CustomerDataSourceDataChange(Sender: TObject; Field: TField);
procedure OrdersDataSourceDataChange(Sender: TObject; Field: TField);
procedure cbxApplyOrdersFilterClick(Sender: TObject);
procedure CalcBtnClick(Sender: TObject);
procedure VariablesBtnClick(Sender: TObject);
procedure ExpressionListboxDblClick(Sender: TObject);
procedure btnDrawGraphClick(Sender: TObject);
procedure RegisterFuncBtnClick(Sender: TObject);
procedure UnregisterBtnClick(Sender: TObject);
procedure RunBtnClick(Sender: TObject);
procedure NewFuncsListboxClick(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure btnAboutClick(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
{ Page 1 - Filter and DBExpression Demo }
Xmax,XMin : double;
OldNumpts,NumPts : longint;
GraphFormula : string[150];
Function CollectGraphOpts : boolean;
Procedure PlotGraph;
Procedure UpdateCustomerGrid;
Procedure UpdateOrdersGrid;
Procedure UpdateOrderCalc;
Procedure RunFunc;
{ RTTI }
public
{ Public declarations }
end;
var
MainDemoFm: TMainDemoFm;
implementation
uses FBMisc,VarDlg,ChartFX,FBHelpFm,demabout,typinfo,WarnDlg,RTTIFm;
{$R *.DFM}
Const ALLTYPES = [vtSTRING,vtINTEGER,vtFLOAT,vtBOOLEAN,vtDATE,vtCHAR,vtANY];
const DBExpr =
'[Customer->Company] + " paid $"+str([Orders->AmountPaid],2) + '+
'" on order #"+Str([Orders->OrderNo])+ " on " + '+
'DateToStr([Orders->SaleDate])+". Payment was by " + '+
'[Orders->PaymentMethod]';
CustExpr = 'Company + " is in " +City+" " +State+" "+Zip';
OrderExpr = '"Customer #"+Str(CustNo)+" Owes $"+str(ItemsTotal-AmountPaid,2) + '+
'" on Order # "+Str(OrderNo)';
Function RemoveCRLF(const s : string):string;
var a,b : string;
begin
SplitByDelim(s,#13#10,a, b);
result := a + b;
end;
procedure TMainDemoFm.btnFunctionsClick(Sender: TObject);
begin
DisplayFunctionList;
end;
procedure TMainDemoFm.FormCreate(Sender: TObject);
var proplist : TStringList;
begin
CustomerTable.Active := True; { Do this only on enter page 1 ?}
OrdersTable.Active := True;
{::::::}
OrdersExpression.Database := OrdersTable.Database;
OrdersExpression.Formula := DBExpr;
{ UpdateOrderCalc }
RunBtn.Enabled := False;
end;
{/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{ Page 1 - Basic Demo }
{::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::}
procedure TMainDemoFm.CalcBtnClick(Sender: TObject);
var s: String;
Procedure DispError;
begin
ResultMemo.Text := SimpleExpression.StatusText;
MessageBeep(MB_ICONHAND);
end;
begin
s := ExpressionCombo.Text;
if (s[1] = ';') OR (s = '') then exit; { ignore comments and blank lines }
with simpleExpression do
begin
Formula := S;
if Status = EXPR_SUCCESS then
begin
ResultMemo.Text := AsString;
if Status = EXPR_SUCCESS then
ExpressionCombo.Items.Add(s)
else
DispError;
end
else
DispError;
end;
end;
procedure TMainDemoFm.VariablesBtnClick(Sender: TObject);
begin
ManageVariables(SimpleExpression.Handle);
end;
procedure TMainDemoFm.ExpressionListboxDblClick(Sender: TObject);
var s : string;
begin
with ExpressionListBox do
if itemIndex > 0 then
begin
s := items[ItemIndex];
if s[1] <> ';' then
ExpressionCombo.Text := s;
end;
end;
{* *}
{* Page 2 - BDE Expression Demo *}
{* Utilizes all the Data-Aware Types *}
{* *}
Procedure TMainDemoFm.UpdateCustomerGrid;
begin
CustomersFilter.Refresh;
CustomerGrid.Invalidate;
CustomerTable.First;
end;
Procedure TMainDemoFm.UpdateOrdersGrid;
begin
OrdersFilter.Refresh;
OrdersGrid.Invalidate;
OrdersTable.First;
end;
Procedure TMainDemoFm.UpdateOrderCalc;
begin
if (not Assigned(OrdersExpression)) or OrdersExpression.isNull then
OrdersResultPanel.Caption := ''
else
OrdersResultPanel.Caption := ' > '+RemoveCRLF(OrdersExpression.AsString);
end;
procedure TMainDemoFm.btnOrdersFilterClick(Sender: TObject);
begin
if BuildDSExpression('Orders Filter Expression',[vtBoolean],
OrdersFilter,OrdersTable) then
UpdateOrdersGrid;
end;
procedure TMainDemoFm.FilterBtnClick(Sender: TObject);
begin
if Bu